package com.zjz.demo.add;

import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/10/08/20:20
 * @Description: 计数器
 * @Target:
 */
public class CountDownLatchTest {
    // 总数是6
    public static void main(String[] args) throws InterruptedException {

        // 必须完成某个任务才能到下一个方法时使用
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"--离开---");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }

        countDownLatch.await(); // 等待计数器归0,然后再向下执行

        System.out.println("Close door");
    }
}
